<% admin_breadcrumb(link_to plural_resource_name(Spree::LegacyUser), spree.admin_users_path) %>
<% admin_breadcrumb(link_to @user.email, edit_admin_user_url(@user)) %>
<% admin_breadcrumb(Spree.t('admin.user.order_history')) %>


<%= render 'spree/admin/users/sidebar' %>
<%= render 'spree/admin/users/tabs', current: :orders %>
<%= render :partial => 'spree/admin/users/user_page_actions' %>

<fieldset data-hook="admin_user_order_history" class="col-xs-9">
  <legend><%= Spree.t(:"admin.user.order_history") %></legend>

  <%= paginate @orders, theme: "solidus_admin" %>

  <% if @orders.any? %>
    <%# TODO add search interface %>
    <table class="index" id="listing_orders" data-hook>
      <colgroup>
         <col style="width: 25%;">
         <col style="width: 25%;">
         <col style="width: 25%;">
         <col style="width: 25%;">
      </colgroup>
      <thead>
        <tr data-hook="admin_orders_index_headers">
          <th><%= sort_link @search, :completed_at,   Spree::Order.human_attribute_name(:completed_at), {}, {:title => 'orders_completed_at_title'} %></th>
          <th><%= sort_link @search, :number,         Spree::Order.human_attribute_name(:number), {}, {:title => 'orders_number_title'} %></th>
          <th><%= sort_link @search, :state,          Spree::Order.human_attribute_name(:state), {}, {:title => 'orders_state_title'} %></th>
          <th><%= sort_link @search, :total,          Spree::Order.human_attribute_name(:total), {}, {:title => 'orders_total_title'} %></th>
        </tr>
      </thead>
      <tbody>
      <% @orders.each do |order| %>
        <tr data-hook="admin_orders_index_rows" class="state-<%= order.state.downcase %> <%= cycle('odd', 'even') %>">
          <td class="align-center order-completed-at"><%= l(order.completed_at.to_date) if order.completed_at %></td>
          <td class="align-center order-number">
            <% if can?([:admin, :edit], order) %>
              <%= link_to order.number, edit_admin_order_path(order) %>
            <% else %>
              <%= order.number %>
            <% end %>
          </td>
          <td class="align-center order-state">
            <div class="state <%= order.state.downcase %>"><%= Spree.t("order_state.#{order.state.downcase}") %></div>
            <% if order.payment_state %>
              <div class="state <%= order.payment_state %>"><%= link_to Spree.t("payment_states.#{order.payment_state}"), admin_order_payments_path(order) %></div>
            <% end %>
            <% if Spree::Order.checkout_step_names.include?(:delivery) && order.shipment_state %>
              <div class="state <%= order.shipment_state %>"><%= Spree.t("shipment_states.#{order.shipment_state}") %></div>
            <% end %>
          </td>
          <td class="align-center order-total"><%= order.display_total.to_html %></td>
        </tr>
      <% end %>
      </tbody>
    </table>
  <% else %>
    <div class="col-xs-9 no-objects-found">
      <%= render 'spree/admin/shared/no_objects_found',
                   resource: Spree::Order,
                   new_resource_url: spree.new_admin_order_path %>
    </div>
  <% end %>

  <%= paginate @orders, theme: "solidus_admin" %>
</fieldset>
